﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>DCTool V1.2——DCMS上传管理具</title>
    <link href="css/flasstool.css" rel="stylesheet" type="text/css" />
    <link href="css/jquery.contextMenu.css" rel="stylesheet" type="text/css" />
	<link type="text/css" rel="stylesheet" href="css/weebox.css" />
    <script language="javascript" type="text/javascript" src="js/jquery.js"></script>
    <script src="js/jquery.contextMenu.js" type="text/javascript"></script>
    <script src="js/jquery.bgiframe.js" type="text/javascript"></script>
    <script src="js/jquery.weebox.js" type="text/javascript"></script>
    <script src="js/swfaddress.js" type="text/javascript"></script>
   <script language="javascript" type="text/javascript">	
    //取cookies函数   
    function getCookie(name)     
    {
        var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
        if(arr != null) return unescape(arr[2]); return null;
    }
    </script>
    <script language="javascript" type="text/javascript">
        var authid=getCookie("AuthId");
       // if(authid==null || authid=="")
        //{
            //alert("登录超时，请重新登录！");
           // top.location.href="../../manage/adminlogin.aspx";
            //20111018date
       // }
        var myUpPath = "Upload/"
	var UpLoadPath = "";
        var UpFolder = ""
		var SortFiled = "time";
		var SortType = "DESC"
		var loading = '<table width=\"90%\" height=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"  align=\"center\"><tr><td align=\"center\" valign=\"middle\"><img src=\"images/Loading.gif\" width=\"220\" height=\"19\" align=\"middle\" /></br>文件读取中 请稍等</td></tr></table>'
		var json = null;
		//双击文件夹或打开文件夹事件
        function getFolderInFile(Path,Key,Type){
            if(Type != "UP"){
                Path = UpFolder + Path;
            }else{
                tempStr = Path.split('/');
                Path = "";
                for(var i = 0;i<tempStr.length-2;i++){
                    Path +=  tempStr[i] + "/"
                }
				if(Path == ""){
					Path = myUpPath; 
				}
            }
			$("#BrowseMain").html(loading);
			
            $.ajax({
               type: "POST",
               url: "aspx/BrowseFile.aspx",
               data: "Operate=Browse&Path="+Path+"&Key="+Key+"&SortFiled="+SortFiled+"&SortType="+SortType,
               success: function(msg){
			  
                 json = eval("["+msg+"]");
				 UpFolder = Path;
                 var str = "";
                 if(UpFolder != "" && Path != myUpPath){
                     img = "icon\\UpFolder.png"
                     clickStr = "ondblclick=\"getFolderInFile('"+Path+"','','UP')\""
                     str += "<div "+clickStr+"  class=\"divbox upFolder\"><dt><table   height=100%   width=100%><tr  valign=middle   align=center><td><img src=\""+img+"\" align=\"absmiddle\"></td></tr></table></dt><b>返回上级</b></div>"
                 }
                 for(var i=0;i<json.length;i++){
                    if(json[i].type == "Folder"){
                        img = "icon\\Folder.png"
                        clickStr = "onclick=\"selectFile(this);\" ondblclick=\"getFolderInFile('"+json[i].name+"/','','DOWN')\""
						onerrorStr = "";
						imgsrc = "";
                    }else{
						if(String(json[i].extension).toLowerCase() == ".gif" || String(json[i].extension).toLowerCase() == ".png" || String(json[i].extension).toLowerCase() == ".jpg"){
                        	var name = json[i].extension.split(".").join("");
							img = "icon/48x48/" + name +".gif";
                        	imgsrc = json[i].path;
							onerrorStr = ""+json[i].extension.split(".").join("")+".gif";
						}else{
							var name = json[i].extension.split(".").join("");
							img = "icon/48x48/" + name +".gif";
							onerrorStr = "default.gif";
							imgsrc ="";
						}
                        clickStr = "onclick=\"selectFile(this);\" ondblclick=\"ChooseOneFile(this);\"";
                    }
                    var filename = json[i].name.split("-")[0]
                    str += "<div "+clickStr+" class=\"divbox div"+json[i].type+"\" id=\"divBox_"+i+"\" value=\""+i+"\" isselect=\"0\"><dt><table   height=100%   width=100%><tr  valign=middle   align=center><td><img src=\""+img+"\" class=\"img_List\" imgsrc=\""+imgsrc+"\" align=\"absmiddle\"  alt=\""+json[i].name+"\" /></td></tr></table></dt><div>"+filename+"</div></div>"
                   
                 }
                  $("#BrowseMain").html(str);
                   
				   $("#nowPath").html(Path.split(myUpPath).join("/"));
				   	$(function(){
					  //当鼠标滑入时将div的class换成divOver
					  $('.divbox').hover(function(){
						$(this).addClass('divOver');  
					   },function(){
						//鼠标离开时移除divOver样式
						$(this).removeClass('divOver'); 
					   }
					  );
					 }); 
				  $("#BrowseMain").contextMenu({
					menu: 'myDivMenu'
					},
						function(action, el, pos) {
						switch(action){
							case "refresh":
								getFolderInFile("","","DOWN");
								break;
							case "openUpFolder":
								getFolderInFile(UpFolder,"","UP");
								break;
							case "upfile":
								showDivUpFileBox(UpFolder);
								break;
							case "newfolder":
								showNewFolder();
								break;	
						}
					});
					//上一级文件夹
					 $("#BrowseMain .upFolder").contextMenu({
					menu: 'myupFolderMenu'
					},
						function(action, el, pos) {
						switch(action){
							case "openUpFolder":
								getFolderInFile(Path,'','UP');
								break;
						}
					});
					//文件上面的右键	
				  $("#BrowseMain .divFile").contextMenu({
					menu: 'myFileMenu'
					},
						function(action, el, pos) {
						var id = $(el).attr('value');
						switch(action){
							case "select":
								ChooseOneFile($("#divBox_"+id));
								break;
							case "see":
							    window.open(json[id].path,"_blank");
								break;
							case "delete":
								DeleteFile($("#divBox_"+id));
								break;	
								
						}
					});	
					//文件夹上的右键
					$("#BrowseMain .divFolder").contextMenu({
					menu: 'myFolderMenu'
					},
						function(action, el, pos) {
						var id = $(el).attr('value');
						switch(action){
							case "open":
								getFolderInFile(json[id].name+"/",'','DOWN');
								break;
							case "upfile":
								showDivUpFileBox(UpFolder+json[id].name+"/");
								break;
							case "delete":
								DeleteFile($("#divBox_"+id));
								break;
							case "newfolder":
								showNewFolder($("#divBox_"+id));
								break;
							case "againfolder":
								showAgainFolder($("#divBox_"+id));
								break;					
						}
					});	
               }
            }); 
           
        }
		//单击文件事件
		function selectFile(ObjThis){
			var ID = $(ObjThis).attr('value');
			var isselect = $("#divBox_"+ID).attr('isselect');
			if(isselect == "0"){
				$("#divBox_"+ID).addClass('selectBox');
				$("#divBox_"+ID).attr('isselect','1');  
			}else{
				$("#divBox_"+ID).removeClass('selectBox');
				$("#divBox_"+ID).attr('isselect','0'); 
			}
		}
		//双击文件或选中文件事件
		function ChooseOneFile(ObjThis){
			selectFile(ObjThis);
			var ID = $(ObjThis).attr('value');
			
			var F=GetQueryString("EditorFuncNum");
			if(F!=null){
				//XHEDITOR返回参数的方法
				upload(json[ID].path);
				//window.close();
			}else{
				//自己的DCTOOL的返回方法
				var inputName=GetQueryString("inputName");
				parent.$.DcTool.close(inputName,json[ID].path);
			}
		}
		//XHEDITOR接口
		function upload(str)
		{
			callback(str);
		}
		function closewindow()
		{
			unloadme();
		}
		//批量选择事件
		function ChooseFile(){
			var BoxAll = $(".divbox[isselect*='1']");
			var choosePath = "";
			for(var i=0;i<BoxAll.length;i++){
				if(choosePath !=""){
					choosePath += "|";
				}
				var ID = $($(".divbox[isselect*='1']").get(i)).attr('value');
				choosePath += json[ID].path
			}
			var F=GetQueryString("CKEditorFuncNum");
			if(F!=null){
				//CKEditor返回参数的方法
				var E=window.top.opener;
				if (E['CKEDITOR']){
					E['CKEDITOR'].tools.callFunction(F,choosePath,"")
				}
				window.close();
			}else{
				//自己的DCTOOL的返回方法
				var inputName=GetQueryString("inputName");
				parent.$.DcTool.close(inputName,choosePath);
			}
			//alert(choosePath)
		}
		//文件夹重命名
		function showAgainFolder(ThisObj){
			var ID = $(ThisObj).attr('value');
			$.weeboxs.open('.AgainFolder', {
						title:'文件夹重命名',
						contentType:'selector',
						width:300, 
						height:50,
						draggable:false,
						onopen:function(box) {
							$("#myAgainFolderName").attr('value',json[ID].name);
						},
						onok:function(box){
							if($("#myAgainFolderName").attr('value') != ""){
								$.ajax({
								   type: "POST",
								   url: "aspx/BrowseFile.aspx",
								   data: "Operate=AGAINFOLDER&Path="+json[ID].path+"&oldname="+encodeURI(json[ID].name)+"&newname="+encodeURI($("#myAgainFolderName").attr('value')),
								   success: function(msg){
										json = eval("["+msg+"]");
										alert(json[0].Message);
										if(json[0].Start == "TRUE"){
											getFolderInFile('','','DOWN');
											box.close();//增加事件方法后需手动关闭弹窗
										}
								   }
								});
							}else{
								alert("目录名不能为空！")
							}
							
						}
					});
		}
		//新建文件夹
		function showNewFolder(ThisObj){
			if(ThisObj != undefined){
				var ID = $(ThisObj).attr('value');
				UpFolder += "/" + json[ID].name +"/";
			}
			$.weeboxs.open('.NewFolder', {
						title:'新建文件夹',
						contentType:'selector',
						width:300, 
						height:50,
						draggable:false,
						onok:function(box){
							if($("#myFolderName").attr('value') != ""){
								var NewPath = UpFolder + $("#myFolderName").attr('value');	
								$.ajax({
								   type: "POST",
								   url: "aspx/BrowseFile.aspx",
								   data: "Operate=NEWFOLDER&Path="+encodeURI(NewPath),
								   success: function(msg){
										json = eval("["+msg+"]");
										alert(json[0].Message);
										if(json[0].Start == "TRUE"){
											getFolderInFile('','','DOWN');
											box.close();//增加事件方法后需手动关闭弹窗
										}
								   }
								});
							}else{
								alert("目录名不能为空！")
							}
							
						}
					});
		}
		//弹出上传窗口
		rnd.today=new Date();    
        rnd.seed=rnd.today.getTime();     
        function rnd() {    
　　　　    rnd.seed = (rnd.seed*9301+49297) % 233280;    
　　　　    return rnd.seed/(233280.0);    
        };    
        function rand(number) {    
　　　　    return Math.ceil(rnd()*number);    
        };
		function showDivUpFileBox(Path){
			UpLoadPath = Path;
			RndValue = rand(10000);    
			$("#uploadFlash").html("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' id='uploadFlash' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0' name='myFlash' width='480' height='300' id='myFlash'><param name='movie' value='src/upFile.swf?UploadPath="+getUpLoadFolderPath()+"&id="+RndValue+"' /><param name='quality' value='height' /><param name='allowScriptAccess' value='always' /><embed src='src/upFile.swf?UploadPath="+getUpLoadFolderPath()+"&id="+RndValue+"' width='480' height='300' quality='high' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' allowscriptaccess='always' name='myFlash'></embed></object>");
			//alert($("#uploadFlash").html())
			//SWFAddress.setValue("/" + escape(UpLoadPath));
			$.weeboxs.open('.boxcontent', {
						title:'文件上传',
						contentType:'selector',
						showButton:false,//不显示按钮栏
						showOk:false,//不显示确定按钮
						showCancel:false,//不显示取消按钮
						width:500, 
						height:300,
						draggable:false
					});
		}
		//对文件进行排序
		function ShorFile(ThisObj){
			var Type = $(ThisObj).attr('type');
			$("a[type*='"+Type+"']").removeClass("checked");
			$(ThisObj).addClass('checked');
			SortFiled = $("a[type*='filed'][class*='checked']").attr('value');
			SortType = $("a[type*='type'][class*='checked']").attr('value');
			getFolderInFile('','','DOWN');
		}
		//删除文件
		function DeleteFile(ThisObj){
			if(confirm("您确认要删除所选择的文件！")){
				var choosePath = "";
				if(ThisObj == undefined){
					var BoxAll = $(".divbox[isselect*='1']");
					for(var i=0;i<BoxAll.length;i++){
						if(choosePath !=""){
							choosePath += "|";
						}
						var ID = $($(".divbox[isselect*='1']").get(i)).attr('value');
						choosePath += json[ID].path + "^" + json[ID].type
					}
				}else{
					var ID = $(ThisObj).attr('value');
					choosePath = json[ID].path + "^" + json[ID].type;
				}
				$.ajax({
				   type: "POST",
				   url: "aspx/BrowseFile.aspx",
				   data: "Operate=DELETEFILE&Path="+choosePath,
				   success: function(msg){
						json = eval("["+msg+"]");
						alert(json[0].Message);
						if(json[0].Start == "TRUE"){
							getFolderInFile('','','DOWN');
						}
				   }
				}); 
			}
		}
		//获取上传的路径
		function getUpLoadFolderPath(){
            //SWFAddress.setValue("/" + escape(UpLoadPath));
			return "/" + UpLoadPath;
		}
		//上传文件后刷新目录
		function setNowFolderPath(){
			UpFolder = "";
			$.weeboxs.close('.boxcontent');
			getFolderInFile(UpLoadPath,"","DOWN")
		}
		//上传文件后刷新目录不关闭
		function setNowFolderPathNoClose(){
			UpFolder = "";
			getFolderInFile(UpLoadPath,"","DOWN")
		}
		//取Url参数
		function GetQueryString(name)
		{    
			var reg=new RegExp("(^|&)"+name+"=([^&]*)(&|$)","i");
			var r=window.location.search.substr(1).match(reg);
			if(r!=null)
			{
				return unescape(r[2])
			}
			return null;     
		}
		//切换视图
		function ChangeBrowse()
		{    
			$(".img_List").each(function(index,domEle){
				var imgsrc=$(domEle).attr("imgsrc").toLowerCase();
				var src=$(domEle).attr("src").toLowerCase();
				if((imgsrc.length>0))
				{
				    $(domEle).attr("width",82);
				    $(domEle).attr("height",82);
					$(domEle).attr("src",imgsrc);
					$(domEle).attr("imgsrc",src);
				}
			});
			
		}
    </script>
    <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>
<body>
    <div id="Main" onclick="$('#drop_sort').attr('style','display:none;');">
            <div class="apptools">
                <div class="apptools-inner">      
                    <a id="toolback" class="btn" href="javascript:void(0)" onclick="getFolderInFile(UpFolder,'','UP')"><span><img src="icon/folder_up.gif" alt="" width="16" height="16" />返回上级</span></a>
                    <span class="edge">|</span>
                    <a id="toolNewDir" class="btn" href="javascript:void(0)" onclick="showNewFolder();"><span><img src="icon/folder_add.gif" alt="" width="16" height="16" />新建目录</span></a>
                    <!--a id="toolMove" class="btn" href="#"><span><img src="icon/file_export.gif" alt="" width="16" height="16" />移动</span></a-->
                    <a id="toolUploadFile" class="btn" href="javascript:void(0)" onclick="showDivUpFileBox(UpFolder);"><span><img src="icon/file_up.gif" alt="" width="16" height="16" />上传</span></a>
                    <span class="edge">|</span>
                    <a id="toolUploadFile" class="btn" href="javascript:void(0)" onclick="ChooseFile();"><span><img src="icon/select.gif" alt="" width="16" height="16" />选择</span></a>
                    <span class="edge">|</span>
                    <a id="toolDelete" class="btn" href="javascript:void(0)" onclick="DeleteFile();"><span><img src="icon/crossout.gif" alt="" width="16" height="16" />删除</span></a>
                    <!--开始-->
                    <span class="edge">|</span>
                    <div > 
                        <a class="btn"  id="toolListView" href="javascript:void(0)" onclick="ChangeBrowse();" title="切换到列表视图"><span><img src="icon/view_thumb.gif" alt="" width="16" height="16" /></span></a>
                    
                        <div class="dropdowndock">
                            <a id="tool_sort" class="btn btn-dropdown" href="javascript:void(0);" title="文件排列方式" onmousemove="$('#drop_sort').css('display','');"><span><img src="icon/order_asc.gif" alt="" width="16" height="16" />排列</span></a>
                            <div class="dropdownmenu-wrap" id="drop_sort" style="display:none;">
                                <div class="dropdownmenu">
                                    <ul class="dropdownmenu-list">
                                        <li><a type="filed"  href="#" value="name" onclick="ShorFile(this);">名称</a></li>
                                        <li><a type="filed"  href="#" value="size" onclick="ShorFile(this);">大小</a></li>
                                        <li><a type="filed" class="checked" href="#" value="time" onclick="ShorFile(this);">创建时间</a></li>
                                        <li><a type="filed"  href="#" value="extension" onclick="ShorFile(this);">类型</a></li>
                                        <li class="dropmenu-split">-</li>
                                        <li><a  type="type" href="#" value="ASC" onclick="ShorFile(this);">顺序</a></li>
                                        <li><a  type="type" class="checked" href="#" value="DESC" onclick="ShorFile(this);">倒序</a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>        
                    </div>
                    <div style="float:right; color:#FF0000;">位置:<span id="nowPath"></span></div>
                    <!--结束-->
                </div>
            </div>
            <div id="BrowseMain">
             
            </div>
    </div>
    <ul id="myDivMenu" class="contextMenu">
      <li class="openUpFolder"><a href="#openUpFolder">上一级文件夹</a></li>
        <li class="upfile"><a href="#upfile">上传文件</a></li>
        <li class="newfolder"><a href="#newfolder">新建文件夹</a></li>
        <li class="delete"><a href="#refresh">刷新文件夹</a></li>
    </ul>
    <ul id="myFileMenu" class="contextMenu">
        <li class="select"><a href="#select">选中文件</a></li>
        <!--li class="edit"><a href="#edit">编辑文件</a></li-->
        <li class="see"><a href="#see">查看文件</a></li>
        <!--li class="export"><a href="#export">移动文件</a></li-->
        <li class="delete"><a href="#delete">删除文件</a></li>
    </ul>
    <ul id="myFolderMenu" class="contextMenu">
        <li class="open"><a href="#open">打开文件夹</a></li>
        <li class="againfolder"><a href="#againfolder">重命名</a></li>
        <li class="newfolder"><a href="#newfolder">新建文件夹</a></li>
        <!--li class="export"><a href="#export">移动文件夹</a></li-->
        <li class="delete"><a href="#delete">删除文件夹</a></li>
        <li class="upfile" ><a href="#upfile">上传文件</a></li>
    </ul>
    <ul id="myupFolderMenu" class="contextMenu">
        <li class="openUpFolder"><a href="#openUpFolder">上一级文件夹</a></li>
    </ul>
    <div  style="display:none"  class="boxcontent" id="uploadFlash">

      
    </div>
<div style="display:none" class="NewFolder">
    	<div style="padding:10px;">
    	目录名称：<input name="myFolderName" id="myFolderName" type="text" class="inputtext"/>
        </div>
    </div>
    <div style="display:none" class="AgainFolder">
    	<div style="padding:10px;">
    	目录名称：<input name="myAgainFolderName" id="myAgainFolderName" type="text" class="inputtext" value="fasdfsa"/>
        </div>
    </div>
    <script>getFolderInFile(myUpPath,"","DOWN");</script>
  
</body>
</html>
